package com.hellogood.yaohuo.client.common;

import java.util.Date;

public class Tools {
	public static int toInteger(Object obj) {
		if (obj == null) {
			return 0;
		} else {
			int length = obj.toString().length();
			for (int i = 0; i < length; i++) {
				if (i == 0) {
					if (obj.toString().charAt(i) == '-') {
						continue;
					}
				}
				if (!Character.isDigit(obj.toString().charAt(i))) {
					return 0;
				}
			}
			return Integer.valueOf(obj.toString());
		}
	}

	public static String getTodayFormattedDate() {
		Date date = new Date();
		int year = date.getYear() + 1900;
		int month = date.getMonth() + 1;
		int day = date.getDate();

		String today = year + "" + (month < 10 ? "0" + month : month) + "" + (day < 10 ? "0" + day : day);
		return today;
	}
}
